
<%@page import="java.util.Vector"%>
<%@page import="accessor.OrderAccessor"%>
<%@page import="accessor.Order"%>
<%@page import="java.util.List"%>
<%@include file="header.jsp" %>
<div id="content">
    <script>
        $(document).ready(function(){
            $("#status_filter").change(function(){
                var statusID = $(this).find("option:selected").val();
                window.location.href = "list_all_order.jsp?status="+statusID;
                $("#status_filter").val(selected_status).attr('selected',true);
            });
        });
    </script>
    <div id="title_content">Order Management</div>
    <%
        int status = request.getParameter("status") != null ? Integer.parseInt(request.getParameter("status")) : 0;
        OrderAccessor orderAccessor = new OrderAccessor();
        List<Order> orderList = orderAccessor.getAllOrders(status);
        List<Vector> statusList = orderAccessor.getAllOrderStatus();

    %>
    <div>
        <select id="status_filter" style="width: 250px;">
            <option value="0">---All---</option>
            <% for (Vector v : statusList) {%>
            <option <%= Integer.parseInt(v.get(0).toString()) ==status?"selected='selected'":""%> value="<%= v.get(0)%>"><%= v.get(1)%></option>
            <%}%>
        </select>
    </div>
    <br/>
    <table class="list" width="100%">
        <thead>
            <tr>
                <th width="60px">ID</th>
                <th>Customer Name</th>
                <th>Total</th>
                <th>Ordered Date</th>
                <th>Scheduled Delivery Date</th>
                <th>Actual Shipping date</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            <% for (Order order : orderList) {%>
            <tr>
                <td>
                    <div id="action">
                        <a class="action_edit" href="orderdetails.jsp?id=<%= order.getOrderID()%>"></a><%= order.getOrderID()%>
                    </div>
                </td>
                <td><%= order.getCustomer().getFirstName() + " " + order.getCustomer().getLastName()%></td>
                <td>$<%= orderAccessor.getTotalPaidByOrder(order.getOrderID())%></td>
                <td><%= order.getOrderDate()%></td>
                <td><%= order.getDeliveryDate()%></td>
                <td><%= order.getActualShippingDate() == null ? "Not Shipped yet" : order.getActualShippingDate()%></td>
                <td><%= order.getStatusName()%></td>
                <td></td>
            </tr>
            <%}%>
        </tbody>
    </table>
</div>
<%@include file="footer.jsp" %>
